package com.rad.datastat.utils;

import android.content.ContentResolver;
import android.content.Context;
import android.provider.Settings;

public class UsbControlUtil {

	private static final String TAG = "UsbDebugControl";

	/**
	 * 获取USB调试模式状态
	 * 
	 * @param context
	 * @return true if UsbDebug is open, false if UsbDebug is close
	 */
	public static boolean isUSBDebugEnable(Context context) {
		ContentResolver contentResolver = context.getContentResolver();
		boolean adbState = (Settings.Secure.getInt(contentResolver, Settings.Secure.ADB_ENABLED, 0) > 0);
		return adbState;
	}

	/**
	 * 关闭ADB
	 * 
	 * @param context
	 */
	public static void disableAdb(Context context) {
		try {
			ContentResolver contentResolver = context.getContentResolver();
			Settings.Secure.putInt(contentResolver, Settings.Secure.ADB_ENABLED, 0);
		} catch (SecurityException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 开启ADB
	 * 
	 * @param context
	 */
	public static void enableAdb(Context context) {
		try {
			ContentResolver contentResolver = context.getContentResolver();
			Settings.Secure.putInt(contentResolver, Settings.Secure.ADB_ENABLED, 1);
		} catch (SecurityException e) {
			e.printStackTrace();
		}
	}

}
